package com.gxitsky.common.utils;

import java.util.Random;
import java.util.UUID;

public class UniqueIdUtil {

    /**
     * 根据当前时间的毫秒值(13位)+3位随机数生成16位的唯一字符串数字;
     *
     * @return String
     */
    public static String millisecondIdStr() {
        long millis = System.currentTimeMillis();
        Random random = new Random();
        int anInt = random.nextInt(999);
        // 如果不足三位前面补0
        String millisecondId = millis + String.format("%03d", anInt);
        return millisecondId;
    }

    /**
     * 转长整型
     *
     * @return
     */
    public static Long millisecondIdLong() {
        return Long.valueOf(millisecondIdStr());
    }

    /**
     * 手机短信验证码:6位数字
     *
     * @return
     */
    public static String getSmsVerifyCode() {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 6; i++) {
            int code = random.nextInt(9);
            sb.append(code);
        }
        return sb.toString();
    }

    /**
     * 生成一个全小写的uuid
     *
     * @return
     */
    public static String getUuid() {
        return UUID.randomUUID().toString().replace("-", "").toLowerCase();
    }

    /**
     * 全大写UUID
     *
     * @return
     */
    public static String getUpperUuid() {
        return getUuid().toUpperCase();
    }

    /**
     * 全小写UUID
     *
     * @return
     */
    public static String getLowerUuid() {
        return getUuid().toLowerCase();
    }

    public static void main(String[] args) {
        System.out.println(getLowerUuid());
    }
}
